package search_res_tab

import (
	"file_explorer/model"
	"file_explorer/service/eventbus"
	"file_explorer/view/components/main_panel/fe_tab"
	"file_explorer/view/store"

	"fyne.io/fyne/v2/container"
)

type SearchResTab struct {
	fe_tab.DefaultTab

	ToolBar   *Toolbar
	FileList  *FileList
	StatusBar *StatusBar

	tabCtx *store.SearchResTabContext
}

func NewSearchResTab(tabCtx store.TabContext) *SearchResTab {
	tab := &SearchResTab{
		tabCtx: tabCtx.(*store.SearchResTabContext),
	}

	// 结果列表
	tab.FileList = NewFileList(tab.tabCtx)
	// 状态栏
	tab.StatusBar = NewStatusBar(tab.tabCtx)
	// 工具栏
	tab.ToolBar = NewToolbar(tab.tabCtx, tab)

	// 文件列表选中状态更新时，刷新状态栏、工具栏
	tab.FileList.Checklist.RegisterConsumer(eventbus.EventKeyWidgetChecklistChange, func(event *model.Event) {
		tab.StatusBar.RefreshData()
		tab.ToolBar.refreshData()
	})

	tab.Container = container.NewBorder(tab.ToolBar.Container, tab.StatusBar.Scroll, nil, nil, tab.FileList.Table)

	return tab
}
